output.js ➔ ???   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
nc 4
dl 0
loc 27
rs 8.5806
nop 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A output.js ➔ ... ➔ ??? 0 7 2
1
const fs = require('fs')
2
const { join } = require('path')
3
const { Writable } = require('stream')
4
5
module.exports = (output, data) => {
6
  if (!data) {
7
    return null
8
  }
9
10
  if (typeof output === 'string') {
11
    // Output as file
12
    const path = join(output)
13
    fs.open(path, fs.W_OK, err => {
14
      if (err) {
15
        console.error(`Cannot write file to ${path}`)
16
        return
17
      }
18
      fs.appendFileSync(path, data + '\r\n')
19
    })
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
20
  } else if (output instanceof Writable) {
21
    // Output as stream
22
    output.write(data + '\r\n')
23
    output.on('error', err => {
24
      console.error(err)
25
    })
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
26
  } else {
27
    // Output as console
28
    console.log(data)
29
    return
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
30
  }
31
}
32